export function get(url, data) {
  return request(url, 'GET', data)
}

export function post(url, data) {
  return request(url, 'POST', data)
}

function request(url, method, data) {
  return new Promise((resolve, reject) => {
    uni.request({
      header,
      data,
      method,
      url,
      success: function(res) {
        if (res.data.code === 200) {
          resolve(res.data)
        } else {
          uni.showToast({
            title: res.data.msg,
            icon: 'none'
          })
          reject(res)
        }
      },
      fail: function(res) {
        uni.showToast({
          title: '网络繁忙中...',
          icon: 'none'
        })
        reject(data)
      }
    })
  })
}
